using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SpriteClasses;

namespace FrostFights
{
    public enum GameState { title, howTo, characterSelect, battleMap01, inGameMenu, gameOver, credits }

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GameState gamestate = GameState.title;
        Map map;

        MultiBackground clouds;
        MultiBackground backgrounds;
        Texture2D background;

        public static Random random = new Random();
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont fontImpact;
        List<Player> Players = new List<Player>();
        Meter[] healthBar = new Meter[4];
        Meter[] ammoMeter = new Meter[4];
        public bool hasReset;
        public bool releasedButton;
        public bool reduceHealth;
        public float meterOldPosition;
        public float meterNewPosition;
        const float HEALTH_DECREASE = 10;
        public static Texture2D snowballImg;
        public static Texture2D iceballImg;
        public static Texture2D iceStarImg;
        public static Texture2D iceSpearImg;
        public static Texture2D icicleImg;
        public static Texture2D grenadeImg;
        public static Vector2 Gravity = new Vector2(0, 300);
        Texture2D blueRobotSheet;
        Texture2D blueRobotArm;
        Texture2D blueRobotHead;
        Texture2D greenRobotSheet;
        Texture2D greenRobotArm;
        Texture2D greenRobotHead;
        Texture2D redRobotSheet;
        Texture2D redRobotArm;
        Texture2D redRobotHead;
        Texture2D orangeRobotSheet;
        Texture2D orangeRobotArm;
        Texture2D orangeRobotHead;
        Texture2D logo; 
        Texture2D titleScreen;
        Texture2D howToScreen;
        Texture2D characterSelectScreen;
        Texture2D gameOverScreen;
        Texture2D creditScreen;
        Vector2 ScreenCentre;
        Vector2 gameOverScreenPosition;
        Vector2 creditScreenPosition;

        Texture2D checkmark;
        public static Boolean[] playersJoined = new Boolean[4];
        int numbPlayers = 0;
        public static Song musicTitleScreen;
        public static Song musicGameTheme;
        public static SoundEffect soundWoosh;
        public static SoundEffect soundSelect;
        public static SoundEffect soundBack;
        public static SoundEffect soundThrowSnowBall;
        public static SoundEffect soundThrowIceBall;
        public static SoundEffect soundThrowSnowBurst;
        public static SoundEffect soundThrowIceSpear;
        public static SoundEffect soundJump;
        public static SoundEffect soundHit3;
        public static SoundEffect soundExplosion2;
        ParticleGenerator snowFall;

        public const int TILE_SIZE = 20;
        public const int NUM_ROWS = 45;
        public const int NUM_COLS = 110;

        // character select screen =====================
        public int player1Choice = -1;
        public int player2Choice = -1;
        public int player3Choice = -1;
        public int player4Choice = -1;
        public GamePadState player1LastGamePadState;
        public GamePadState player2LastGamePadState;
        public GamePadState player3LastGamePadState;
        public GamePadState player4LastGamePadState;
        public bool isPlayer1Ready = false;
        public bool isPlayer2Ready = false;
        public bool isPlayer3Ready = false;
        public bool isPlayer4Ready = false;
        public int numPlayersReady = 0;
        public List<Texture2D> robots = new List<Texture2D>();
        public List<Texture2D> robotHeads = new List<Texture2D>();
        public List<Texture2D> robotArms = new List<Texture2D>();
        // =============================================
        // in-Game menu items
        Texture2D inGameMenu;
        SpriteFont inGameMenuFont;
        Sprite[] menuSelectors = new Sprite[2];
        Vector2[] inGameOptionPosition = new Vector2[2];
        string[] inGameOption = new String[2];
        int inGameOptionToggle = 1;
        string inGameMenuInfo;

        KeyboardState keyState;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferWidth = NUM_COLS * 16;
            graphics.PreferredBackBufferHeight = NUM_ROWS * TILE_SIZE;
            graphics.IsFullScreen = true;
        }


        protected override void Initialize()
        {
            for (int i = 0; i < playersJoined.Length; i++)
            {
                playersJoined[i] = false;
            }

            map = new Map();
            // Create inGameMenu messages
            inGameOption[1] = "Continue";
            inGameOption[0] = "Exit";
            creditScreenPosition.Y = GraphicsDevice.Viewport.Height;

            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Menu
            // Create inGameMenu background and selectors
            inGameMenuFont = Content.Load<SpriteFont>("gothic");
            inGameMenu = Content.Load<Texture2D>("Images/Menu");
            for (int i = 0; i < menuSelectors.Length; i++)
                menuSelectors[i] = new Sprite(Content.Load<Texture2D>("Images/snowFlake1"), Vector2.Zero, Vector2.Zero, 0.02f, 1f, SpriteEffects.None, 0f);
            // Create inGameMenu message locations
            for (int i = 0; i < inGameOption.Length; i++)
                inGameOptionPosition[i] = new Vector2(GraphicsDevice.Viewport.Width / 2 - inGameMenuFont.MeasureString(inGameOption[i]).X / 2 + inGameMenuFont.Spacing,
                    GraphicsDevice.Viewport.Height / 2 - inGameMenuFont.MeasureString(inGameOption[i]).Y / 2 + inGameMenuFont.LineSpacing - i * 70);
            //Backgrounds
            background = Content.Load<Texture2D>("Images/Bg5");
            backgrounds = new MultiBackground(GraphicsDevice);
            backgrounds.AddLayer(Content.Load<Texture2D>("Images/Bg1"), 0.3f, 0);
            backgrounds.AddLayer(Content.Load<Texture2D>("Images/Bg2"), 0.4f, 0);
            backgrounds.AddLayer(Content.Load<Texture2D>("Images/Bg3"), 0.5f, 0);
            backgrounds.AddLayer(Content.Load<Texture2D>("Images/Bg4"), 0.6f, 0);
            clouds = new MultiBackground(GraphicsDevice);
            //clouds.AddLayer(Content.Load<Texture2D>("Images/Backgrounds3"), 0f, 30);
            clouds.AddLayer(Content.Load<Texture2D>("Images/Backgrounds2"), 0.1f, -20);
            clouds.SetMoveLeftRight();
            clouds.StartMoving();
            //Fonts
            fontImpact = Content.Load<SpriteFont>("impact");
            //Graphics:
            spriteBatch = new SpriteBatch(GraphicsDevice);
            blueRobotSheet = Content.Load<Texture2D>("Images/blueRobotSpritesheet");
            blueRobotArm = Content.Load<Texture2D>("Images/blueArm");
            blueRobotHead = Content.Load<Texture2D>("Images/blueHead");
            greenRobotSheet = Content.Load<Texture2D>("Images/greenRobotSpritesheet");
            greenRobotArm = Content.Load<Texture2D>("Images/greenArm");
            greenRobotHead = Content.Load<Texture2D>("Images/greenHead");
            redRobotSheet = Content.Load<Texture2D>("Images/redRobotSpritesheet");
            redRobotArm = Content.Load<Texture2D>("Images/redArm");
            redRobotHead = Content.Load<Texture2D>("Images/redHead");
            orangeRobotSheet = Content.Load<Texture2D>("Images/orangeRobotSpritesheet");
            orangeRobotArm = Content.Load<Texture2D>("Images/orangeArm");
            orangeRobotHead = Content.Load<Texture2D>("Images/orangeHead");
            checkmark = Content.Load<Texture2D>("Images/checkmark");
            logo = Content.Load<Texture2D>("Images/frostbyte");
            snowballImg = Content.Load<Texture2D>("Images/snowball");
            iceballImg = Content.Load<Texture2D>("Images/iceball");
            iceStarImg = Content.Load<Texture2D>("Images/iceStar");
            iceSpearImg = Content.Load<Texture2D>("Images/iceSpear");
            icicleImg = Content.Load<Texture2D>("Images/icicle");
            grenadeImg = Content.Load<Texture2D>("Images/grenade");
            titleScreen = Content.Load<Texture2D>("Images/titleScreen");
            howToScreen = Content.Load<Texture2D>("Images/howToScreen");
            characterSelectScreen = Content.Load<Texture2D>("Images/characterSelectScreen");
            gameOverScreen = Content.Load<Texture2D>("Images/winLoseScreen");
            creditScreen = Content.Load<Texture2D>("Images/creditScreen");
            robots.Add(orangeRobotSheet);
            robots.Add(blueRobotSheet);
            robots.Add(redRobotSheet);
            robots.Add(greenRobotSheet);
            robotArms.Add(orangeRobotArm);
            robotArms.Add(blueRobotArm);
            robotArms.Add(redRobotArm);
            robotArms.Add(greenRobotArm);
            robotHeads.Add(orangeRobotHead);
            robotHeads.Add(blueRobotHead);
            robotHeads.Add(redRobotHead);
            robotHeads.Add(greenRobotHead);


            //Audio:
            musicTitleScreen = Content.Load<Song>("Soundtrack/RapidMagic");
            musicGameTheme = Content.Load<Song>("Soundtrack/WarDeception");
            soundSelect = Content.Load<SoundEffect>("SoundEffects/Select");
            soundBack = Content.Load<SoundEffect>("SoundEffects/Back");
            soundWoosh = Content.Load<SoundEffect>("SoundEffects/Woosh");
            soundThrowSnowBall = Content.Load<SoundEffect>("SoundEffects/ThrowSnowBall");
            soundThrowSnowBurst = Content.Load<SoundEffect>("SoundEffects/ThrowSnowBall");
            soundThrowIceBall = Content.Load<SoundEffect>("SoundEffects/ThrowIceBall");
            soundThrowIceSpear = Content.Load<SoundEffect>("SoundEffects/ThrowIceSpear");
            soundJump = Content.Load<SoundEffect>("SoundEffects/Jump");
            soundHit3 = Content.Load<SoundEffect>("SoundEffects/Hit3");
            soundExplosion2 = Content.Load<SoundEffect>("SoundEffects/Explosion2");

            snowFall = new ParticleGenerator(Content.Load<Texture2D>("Images/snowflake"),
                GraphicsDevice.Viewport.Width, 50);

            //--------------------------------------------------------
            //Initialization code that requires loaded content to run:
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(musicTitleScreen);
            //--------------------------------------------------------

            Tiles.Content = Content;
            map.Generate(new int[,]
            {
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
                {3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
            }, TILE_SIZE);
        }


        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected void UpdateCharacterSelection()
        {
            // For testing multiple players without using GamePads
            // keyState = Keyboard.GetState();


            // PLAYER 1 =======================================================================
            if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed
                && !isPlayer1Ready
                && playersJoined[0])
            {
                // Player is ready to play
                isPlayer1Ready = true;
                numPlayersReady++;
                soundWoosh.Play();
            }
            else if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed
                && isPlayer1Ready
                && playersJoined[0])
            {
                // Player is not ready to play yet
                isPlayer1Ready = false;
                numPlayersReady--;
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed
                && player1LastGamePadState.DPad.Left != ButtonState.Pressed
                && !isPlayer1Ready
                && playersJoined[0])
            {
                // Switch character choice
                player1Choice--;
                if (player1Choice < 0)
                {
                    player1Choice = robotHeads.Count - 1;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed
                && player1LastGamePadState.DPad.Right != ButtonState.Pressed
                && !isPlayer1Ready
                && playersJoined[0])
            {
                // Switch character choice
                player1Choice++;
                if (player1Choice > robotHeads.Count - 1)
                {
                    player1Choice = 0;
                }
                soundSelect.Play();
            }
            else if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter)) && !playersJoined[0])
            {
                // Begin character selection
                playersJoined[0] = true;
                player1Choice = 0;
                numbPlayers += 1;
                soundWoosh.Play();
            }




            // PLAYER 2 =======================================================================
            if (GamePad.GetState(PlayerIndex.Two).Buttons.A == ButtonState.Pressed
                && !isPlayer2Ready
                && playersJoined[1])
            {
                // Player is ready to play
                isPlayer2Ready = true;
                numPlayersReady++;
                soundWoosh.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Two).Buttons.B == ButtonState.Pressed
                && isPlayer2Ready
                && playersJoined[1])
            {
                // Player is not ready to play yet
                isPlayer2Ready = false;
                numPlayersReady--;
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Two).DPad.Left == ButtonState.Pressed
                && player2LastGamePadState.DPad.Left != ButtonState.Pressed
                && !isPlayer2Ready
                && playersJoined[1])
            {
                // Switch character choice
                player2Choice--;
                if (player2Choice < 0)
                {
                    player2Choice = robotHeads.Count - 1;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Two).DPad.Right == ButtonState.Pressed
                && player2LastGamePadState.DPad.Right != ButtonState.Pressed
                && !isPlayer2Ready
                && playersJoined[1])
            {
                // Switch character choice
                player2Choice++;
                if (player2Choice > robotHeads.Count - 1)
                {
                    player2Choice = 0;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Two).Buttons.Start == ButtonState.Pressed && !playersJoined[1])
            {
                // Begin character selection
                playersJoined[1] = true;
                player2Choice = 1;
                numbPlayers += 1;
                soundWoosh.Play();
            }




            // PLAYER 3 =======================================================================
            if (GamePad.GetState(PlayerIndex.Three).Buttons.A == ButtonState.Pressed
                && !isPlayer3Ready
                && playersJoined[2])
            {
                // Player is ready to play
                isPlayer3Ready = true;
                numPlayersReady++;
                soundWoosh.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Three).Buttons.B == ButtonState.Pressed
                && isPlayer3Ready
                && playersJoined[2])
            {
                // Player is not ready to play yet
                isPlayer3Ready = false;
                numPlayersReady--;
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Three).DPad.Left == ButtonState.Pressed
                && player3LastGamePadState.DPad.Left != ButtonState.Pressed
                && !isPlayer3Ready
                && playersJoined[2])
            {
                // Switch character choice
                player3Choice--;
                if (player3Choice < 0)
                {
                    player3Choice = robotHeads.Count - 1;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Three).DPad.Right == ButtonState.Pressed
                && player3LastGamePadState.DPad.Right != ButtonState.Pressed
                && !isPlayer3Ready
                && playersJoined[2])
            {
                // Switch character choice
                player3Choice++;
                if (player3Choice > robotHeads.Count - 1)
                {
                    player3Choice = 0;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Three).Buttons.Start == ButtonState.Pressed && !playersJoined[2])
            {
                // Begin character selection
                playersJoined[2] = true;
                player3Choice = 2;
                numbPlayers += 1;
                soundWoosh.Play();
            }




            // PLAYER 4 =======================================================================
            if (GamePad.GetState(PlayerIndex.Four).Buttons.A == ButtonState.Pressed
                && !isPlayer4Ready
                && playersJoined[3])
            {
                // Player is ready to play
                isPlayer4Ready = true;
                numPlayersReady++;
                soundWoosh.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Four).Buttons.B == ButtonState.Pressed
                && isPlayer4Ready
                && playersJoined[3])
            {
                // Player is not ready to play yet
                isPlayer4Ready = false;
                numPlayersReady--;
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Four).DPad.Left == ButtonState.Pressed
                && player4LastGamePadState.DPad.Left != ButtonState.Pressed
                && !isPlayer4Ready
                && playersJoined[3])
            {
                // Switch character choice
                player4Choice--;
                if (player4Choice < 0)
                {
                    player4Choice = robotHeads.Count - 1;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Four).DPad.Right == ButtonState.Pressed
                && player4LastGamePadState.DPad.Right != ButtonState.Pressed
                && !isPlayer4Ready
                && playersJoined[3])
            {
                // Switch character choice
                player4Choice++;
                if (player4Choice > robotHeads.Count - 1)
                {
                    player4Choice = 0;
                }
                soundSelect.Play();
            }
            else if (GamePad.GetState(PlayerIndex.Four).Buttons.Start == ButtonState.Pressed && !playersJoined[3])
            {
                // Begin character selection
                playersJoined[3] = true;
                player4Choice = 3;
                numbPlayers += 1;
                soundWoosh.Play();
            }
        }


        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();

            switch (gamestate)
            {
                case GameState.title:
                    if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed && player1LastGamePadState.Buttons.A == ButtonState.Released)
                        gamestate = GameState.howTo;
                    break;
                case GameState.howTo:
                    if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed && player1LastGamePadState.Buttons.A == ButtonState.Released)
                        gamestate = GameState.characterSelect;
                    break;
                case GameState.characterSelect:
                    snowFall.Update(gameTime, GraphicsDevice);
                    UpdateCharacterSelection();

                    // When all the players are ready
                    if (numPlayersReady == numbPlayers && numbPlayers > 0)
                    {
                        if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed
                            || GamePad.GetState(PlayerIndex.Two).Buttons.Y == ButtonState.Pressed
                            || GamePad.GetState(PlayerIndex.Three).Buttons.Y == ButtonState.Pressed
                            || GamePad.GetState(PlayerIndex.Four).Buttons.Y == ButtonState.Pressed)
                        {
                            gamestate = GameState.battleMap01;
                            MediaPlayer.Play(musicGameTheme);

                            if (isPlayer1Ready)
                            {
                                Players.Add(new Player(robots[player1Choice], robotArms[player1Choice], 1, PlayerIndex.One, Content, graphics));
                                //Health bar
                                healthBar[0] = new Meter(Content, Players[0]);
                                ammoMeter[0] = new Meter(Content, Players[0]);
                                ammoMeter[0].ChangeTexture("ammoBar");
                                meterNewPosition = healthBar[0].meterRect.Width - HEALTH_DECREASE;
                            }
                            if (isPlayer2Ready)
                            {
                                Players.Add(new Player(robots[player2Choice], robotArms[player2Choice], 2, PlayerIndex.Two, Content, graphics));
                                //Health bar
                                healthBar[1] = new Meter(Content, Players[1]);
                                ammoMeter[1] = new Meter(Content, Players[1]);
                                ammoMeter[1].ChangeTexture("ammoBar");
                                meterNewPosition = healthBar[1].meterRect.Width - HEALTH_DECREASE;
                            }
                            if (isPlayer3Ready)
                            {
                                Players.Add(new Player(robots[player3Choice], robotArms[player3Choice], 3, PlayerIndex.Three, Content, graphics));
                                //Health bar
                                healthBar[2] = new Meter(Content, Players[2]);
                                ammoMeter[2] = new Meter(Content, Players[2]);
                                ammoMeter[2].ChangeTexture("ammoBar");
                                meterNewPosition = healthBar[2].meterRect.Width - HEALTH_DECREASE;
                            }
                            if (isPlayer4Ready)
                            {
                                Players.Add(new Player(robots[player4Choice], robotArms[player4Choice], 4, PlayerIndex.Four, Content, graphics));
                                //Health bar
                                healthBar[3] = new Meter(Content, Players[3]);
                                ammoMeter[3] = new Meter(Content, Players[3]);
                                ammoMeter[3].ChangeTexture("ammoBar");
                                meterNewPosition = healthBar[3].meterRect.Width - HEALTH_DECREASE;
                            }
                        }
                    }
                    break;
                case GameState.battleMap01: // ---------------------------- Main Gameplay Area

                    if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed)
                    {
                        releasedButton = true;
                    }
                    if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Released)
                    {
                        if (releasedButton)
                        {
                            reduceHealth = true;
                            releasedButton = false;
                        }
                    }

                    foreach (Player player in Players)
                        foreach (CollisionTiles tile in map.CollisionTiles)
                        {
                            player.Collision(tile.Rectangle, map.Width, map.Height);
                        }

                    if (GamePad.GetState(PlayerIndex.One).Buttons.LeftStick == ButtonState.Pressed)
                    {
                        gamestate = GameState.gameOver;

                        //RESET PLAYERS ===================================================================
                        numPlayersReady = 0;
                        isPlayer1Ready = false;
                        isPlayer2Ready = false;
                        isPlayer3Ready = false;
                        isPlayer4Ready = false;
                    }
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
                    {
                        gamestate = GameState.inGameMenu;
                    }

                    Tick(gameTime);
                    break;
                case GameState.inGameMenu: 
                    GamePadState player1GamePadState = GamePad.GetState(PlayerIndex.One);

                    // Toggle menu options
                    if (player1GamePadState.ThumbSticks.Left.Y > 0.5 && player1LastGamePadState.ThumbSticks.Left.Y < 0.5)
                    {
                        inGameOptionToggle++;
                    }
                    else if (player1GamePadState.ThumbSticks.Left.Y > -0.5 && player1LastGamePadState.ThumbSticks.Left.Y < -0.5)
                    {
                        inGameOptionToggle--;
                    }

                    if (inGameOptionToggle < 0)
                        inGameOptionToggle = 1;
                    else if (inGameOptionToggle > 1)
                        inGameOptionToggle = 0;

                    // Menu options
                    if (player1GamePadState.Buttons.A == ButtonState.Pressed)
                    {
                        switch (inGameOptionToggle)
                        {
                            case 1:
                                gamestate = GameState.battleMap01;
                                break;
                            case 0:
                                Exit();
                                break;
                        }
                    }
                    // Update position of snowflake selectors
                    for (int i = 0; i < menuSelectors.Length; i++)
                        menuSelectors[i].Update(gameTime);

                    menuSelectors[0].Position = new Vector2(inGameOptionPosition[inGameOptionToggle].X + inGameMenuFont.MeasureString(inGameOption[inGameOptionToggle]).X / 2 - inGameMenuFont.Spacing - 120,
                        inGameOptionPosition[inGameOptionToggle].Y + inGameMenuFont.MeasureString(inGameOption[inGameOptionToggle]).Y / 2);
                    menuSelectors[1].Position = new Vector2(inGameOptionPosition[inGameOptionToggle].X + inGameMenuFont.MeasureString(inGameOption[inGameOptionToggle]).X / 2 - inGameMenuFont.Spacing + 120,
                        inGameOptionPosition[inGameOptionToggle].Y + inGameMenuFont.MeasureString(inGameOption[inGameOptionToggle]).Y / 2);

                    player1LastGamePadState = GamePad.GetState(PlayerIndex.One);
                    break;
                case GameState.gameOver:

                    snowFall.Update(gameTime, GraphicsDevice);
                    UpdateCharacterSelection();

                    if (numPlayersReady == numbPlayers && numbPlayers > 0)
                    {
                        gamestate = GameState.credits;
                    }

                    break;
                case GameState.credits:
                    creditScreenPosition.X = GraphicsDevice.Viewport.Width / 2 - creditScreen.Width / 2;
                    creditScreenPosition.Y -= 2;
                    break;
            }

            player1LastGamePadState = GamePad.GetState(PlayerIndex.One);
            player2LastGamePadState = GamePad.GetState(PlayerIndex.Two);
            player3LastGamePadState = GamePad.GetState(PlayerIndex.Three);
            player4LastGamePadState = GamePad.GetState(PlayerIndex.Four);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // I put these here so repeated draw methods can be easily called
            // so if a player pushes start to go to inGame menu, we just call DrawStuff again, as below, keeping everything in background still drawn, but not updating.
            switch (gamestate)
            {
                case GameState.title:
                    DrawTitle(gameTime, spriteBatch);
                    break;
                case GameState.howTo:
                    spriteBatch.Begin();
                    spriteBatch.Draw(howToScreen, Vector2.Zero, Color.White);
                    spriteBatch.End();
                    break;
                case GameState.characterSelect:
                    DrawCharacterSelectScreen(gameTime, spriteBatch);
                    break;
                case GameState.battleMap01:
                    DrawStuff(gameTime, spriteBatch); // keeps initial game loop looking clean
                    break;
                case GameState.inGameMenu:
                    DrawStuff(gameTime, spriteBatch);
                    spriteBatch.Begin();
                    // Draw Menu background for menu options
                    spriteBatch.Draw(inGameMenu, new Vector2(GraphicsDevice.Viewport.Width / 2 - inGameMenu.Width/2,
                        GraphicsDevice.Viewport.Height / 2 - inGameMenu.Height/2), Color.White);
                    // Draw Menu text for menu options
                    for (int i = 0; i < inGameOption.Length; i++)
                        spriteBatch.DrawString(inGameMenuFont, inGameOption[i], inGameOptionPosition[i], Color.White);  
                    // Draw morphballs as menu selection indicators. Positioning is done in Game1 Update.
                    for (int i = 0; i < menuSelectors.Length; i++)
                        menuSelectors[i].Draw(gameTime, spriteBatch);
                    // Menu help info in corner
                    spriteBatch.End();
                    break;
                case GameState.gameOver:
                    DrawGameOverScreen(gameTime, spriteBatch);
                    break;
                case GameState.credits:
                    DrawCredits();
                    break;
            }

            base.Draw(gameTime);
        }

        // METHOD FOR DRAWING
        public void DrawTitle(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(titleScreen, Vector2.Zero, Color.White);
            spriteBatch.End();
        }

        public void DrawStuff(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(background, Vector2.Zero, Color.White);
            spriteBatch.End();
            backgrounds.Draw();
            clouds.Draw();
            spriteBatch.Begin();
            //temporary logo drawing
            map.Draw(spriteBatch);
            if (Players.Count > 0)
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    Players[i].Draw(gameTime, spriteBatch);
                    healthBar[i].DrawMeter(spriteBatch);
                    ammoMeter[i].DrawMeter(spriteBatch);
                }
            }
            snowFall.Draw(spriteBatch);
            spriteBatch.End();

        }


        public void DrawCharacterSelectScreen(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            ScreenCentre = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);

            spriteBatch.Draw(characterSelectScreen, ScreenCentre, null, Color.White, 0.0f, new Vector2(characterSelectScreen.Width / 2, characterSelectScreen.Height / 2), 1.0f, SpriteEffects.None, 1.0f);

            // draw the robot heads

            if (player1Choice >= 0)
            {
                spriteBatch.Draw(robotHeads[player1Choice], new Vector2(ScreenCentre.X - 645f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer1Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X - 645f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (player2Choice >= 0)
            {
                spriteBatch.Draw(robotHeads[player2Choice], new Vector2(ScreenCentre.X - 245f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer2Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X - 245f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (player3Choice >= 0)
            {
                spriteBatch.Draw(robotHeads[player3Choice], new Vector2(ScreenCentre.X + 160f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer3Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X + 160f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (player4Choice >= 0)
            {
                spriteBatch.Draw(robotHeads[player4Choice], new Vector2(ScreenCentre.X + 560f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer4Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X + 560f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            snowFall.Draw(spriteBatch);
            spriteBatch.End();
        }

        public void DrawGameOverScreen(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (hasReset == false)
            {
                //RESET PLAYERS ===================================================================
                hasReset = true;
                numPlayersReady = 0;
                isPlayer1Ready = false;
                isPlayer2Ready = false;
                isPlayer3Ready = false;
                isPlayer4Ready = false;
            }

            spriteBatch.Begin();
            gameOverScreenPosition = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);

            spriteBatch.Draw(gameOverScreen, gameOverScreenPosition, null, Color.White, 0.0f, new Vector2(gameOverScreen.Width / 2, gameOverScreen.Height / 2), 1.0f, SpriteEffects.None, 1.0f);

            string winner = "PLAYER 1";
            spriteBatch.DrawString(fontImpact, winner, new Vector2(GraphicsDevice.Viewport.Width / 2 - fontImpact.MeasureString(winner).X / 2, gameOverScreenPosition.Y / 6), Color.Black);

            if (numbPlayers > 0)
            {
                spriteBatch.Draw(robotHeads[player1Choice], new Vector2(ScreenCentre.X - 645f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer1Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X - 645f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (numbPlayers > 1)
            {
                spriteBatch.Draw(robotHeads[player2Choice], new Vector2(ScreenCentre.X - 245f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer2Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X - 245f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (numbPlayers > 2)
            {
                spriteBatch.Draw(robotHeads[player3Choice], new Vector2(ScreenCentre.X + 160f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer3Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X + 160f, ScreenCentre.Y + 130f), Color.White);
                }
            }
            if (numbPlayers > 3)
            {
                spriteBatch.Draw(robotHeads[player4Choice], new Vector2(ScreenCentre.X + 560f - 40f, ScreenCentre.Y + 70f - 40f), Color.White);
                if (isPlayer4Ready)
                {
                    spriteBatch.Draw(checkmark, new Vector2(ScreenCentre.X + 560f, ScreenCentre.Y + 130f), Color.White);
                }
            }

            snowFall.Draw(spriteBatch);
            spriteBatch.End();
        }

        public void DrawCredits()
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            if (creditScreenPosition.Y > -2000)
                spriteBatch.Draw(creditScreen, creditScreenPosition, Color.White);
            else
                Exit();
            spriteBatch.End();
        }


        public void Tick(GameTime gameTime) // updating the game
        {
            clouds.Update(gameTime);
            backgrounds.Update(gameTime);
            snowFall.Update(gameTime, GraphicsDevice);
            if (Players.Count > 0)
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    Players[i].Update(gameTime, GraphicsDevice, map);
                    Players[i].CheckHits(Players);
                    healthBar[i].MoveMeter(gameTime, Players[i]);
                    ammoMeter[i].position = new Vector2(Players[i].Position.X - 38, Players[i].Position.Y + Players[i].TextureImage.Height / 2 + ammoMeter[i].meterTexture.Height);
                    ammoMeter[i].backingPosition = new Vector2(ammoMeter[i].position.X - 1, ammoMeter[i].position.Y - 1);
                    ammoMeter[i].meterRect.Width = (int)(Players[i].ammoAmount);
                    healthBar[i].Update(Players[i]);
                    if (reduceHealth)                               //If player got hit then health needs to decrease
                    {
                        healthBar[i].meterRect.Width -= 1;          //Slowly decreases until its at the new health
                        UpdateHealthBar(healthBar[i]);
                    }
                }
            }
        }

        public void UpdateHealthBar(Meter healthBar)    //Resets the health bar after it has decreased
        {
            if (healthBar.meterRect.Width == meterNewPosition)
            {
                meterOldPosition = meterNewPosition;
                meterNewPosition -= HEALTH_DECREASE;
                healthBar.meterRect.Width = (int)meterOldPosition;
                reduceHealth = false;
            }
        }
    }
}
